<!doctype html>
<html class="no-js" lang="en" data-content_root="./">
  <head><meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1"/>
    <meta name="color-scheme" content="light dark"><meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="TikTokLive package" href="TikTokLive.html" />

    <!-- Generated with Sphinx 7.4.7 and Furo 2024.08.06 -->
        <title>TikTokLive v6.6.5</title>
      <link rel="stylesheet" type="text/css" href="_static/pygments.css?v=a746c00c" />
    <link rel="stylesheet" type="text/css" href="_static/styles/furo.css?v=354aac6f" />
    <link rel="stylesheet" type="text/css" href="_static/css/rtd_sphinx_search.min.css?v=e72958e9" />
    <link rel="stylesheet" type="text/css" href="_static/styles/furo-extensions.css?v=302659d7" />
    <link rel="stylesheet" type="text/css" href="_static/css/custom.css?v=ff85bd92" />
    
    


<style>
  body {
    --color-code-background: #f8f8f8;
  --color-code-foreground: black;
  
  }
  @media not print {
    body[data-theme="dark"] {
      --color-code-background: #202020;
  --color-code-foreground: #d0d0d0;
  --color-problematic: #80aeef;
  --sidebar-filter: invert(0.95);
  
    }
    @media (prefers-color-scheme: dark) {
      body:not([data-theme="light"]) {
        --color-code-background: #202020;
  --color-code-foreground: #d0d0d0;
  --color-problematic: #80aeef;
  --sidebar-filter: invert(0.95);
  
      }
    }
  }
</style></head>
  <body>
    
    <script>
      document.body.dataset.theme = localStorage.getItem("theme") || "auto";
    </script>
    

<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
  <symbol id="svg-toc" viewBox="0 0 24 24">
    <title>Contents</title>
    <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 1024 1024">
      <path d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM115.4 518.9L271.7 642c5.8 4.6 14.4.5 14.4-6.9V388.9c0-7.4-8.5-11.5-14.4-6.9L115.4 505.1a8.74 8.74 0 0 0 0 13.8z"/>
    </svg>
  </symbol>
  <symbol id="svg-menu" viewBox="0 0 24 24">
    <title>Menu</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-menu">
      <line x1="3" y1="12" x2="21" y2="12"></line>
      <line x1="3" y1="6" x2="21" y2="6"></line>
      <line x1="3" y1="18" x2="21" y2="18"></line>
    </svg>
  </symbol>
  <symbol id="svg-arrow-right" viewBox="0 0 24 24">
    <title>Expand</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-chevron-right">
      <polyline points="9 18 15 12 9 6"></polyline>
    </svg>
  </symbol>
  <symbol id="svg-sun" viewBox="0 0 24 24">
    <title>Light mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="feather-sun">
      <circle cx="12" cy="12" r="5"></circle>
      <line x1="12" y1="1" x2="12" y2="3"></line>
      <line x1="12" y1="21" x2="12" y2="23"></line>
      <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
      <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
      <line x1="1" y1="12" x2="3" y2="12"></line>
      <line x1="21" y1="12" x2="23" y2="12"></line>
      <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
      <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
    </svg>
  </symbol>
  <symbol id="svg-moon" viewBox="0 0 24 24">
    <title>Dark mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-moon">
      <path stroke="none" d="M0 0h24v24H0z" fill="none" />
      <path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z" />
    </svg>
  </symbol>
  <symbol id="svg-sun-with-moon" viewBox="0 0 24 24">
    <title>Auto light/dark, in light mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1" stroke-linecap="round" stroke-linejoin="round"
      class="icon-custom-derived-from-feather-sun-and-tabler-moon">
      <path style="opacity: 50%" d="M 5.411 14.504 C 5.471 14.504 5.532 14.504 5.591 14.504 C 3.639 16.319 4.383 19.569 6.931 20.352 C 7.693 20.586 8.512 20.551 9.25 20.252 C 8.023 23.207 4.056 23.725 2.11 21.184 C 0.166 18.642 1.702 14.949 4.874 14.536 C 5.051 14.512 5.231 14.5 5.411 14.5 L 5.411 14.504 Z"/>
      <line x1="14.5" y1="3.25" x2="14.5" y2="1.25"/>
      <line x1="14.5" y1="15.85" x2="14.5" y2="17.85"/>
      <line x1="10.044" y1="5.094" x2="8.63" y2="3.68"/>
      <line x1="19" y1="14.05" x2="20.414" y2="15.464"/>
      <line x1="8.2" y1="9.55" x2="6.2" y2="9.55"/>
      <line x1="20.8" y1="9.55" x2="22.8" y2="9.55"/>
      <line x1="10.044" y1="14.006" x2="8.63" y2="15.42"/>
      <line x1="19" y1="5.05" x2="20.414" y2="3.636"/>
      <circle cx="14.5" cy="9.55" r="3.6"/>
    </svg>
  </symbol>
  <symbol id="svg-moon-with-sun" viewBox="0 0 24 24">
    <title>Auto light/dark, in dark mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1" stroke-linecap="round" stroke-linejoin="round"
      class="icon-custom-derived-from-feather-sun-and-tabler-moon">
      <path d="M 8.282 7.007 C 8.385 7.007 8.494 7.007 8.595 7.007 C 5.18 10.184 6.481 15.869 10.942 17.24 C 12.275 17.648 13.706 17.589 15 17.066 C 12.851 22.236 5.91 23.143 2.505 18.696 C -0.897 14.249 1.791 7.786 7.342 7.063 C 7.652 7.021 7.965 7 8.282 7 L 8.282 7.007 Z"/>
      <line style="opacity: 50%" x1="18" y1="3.705" x2="18" y2="2.5"/>
      <line style="opacity: 50%" x1="18" y1="11.295" x2="18" y2="12.5"/>
      <line style="opacity: 50%" x1="15.316" y1="4.816" x2="14.464" y2="3.964"/>
      <line style="opacity: 50%" x1="20.711" y1="10.212" x2="21.563" y2="11.063"/>
      <line style="opacity: 50%" x1="14.205" y1="7.5" x2="13.001" y2="7.5"/>
      <line style="opacity: 50%" x1="21.795" y1="7.5" x2="23" y2="7.5"/>
      <line style="opacity: 50%" x1="15.316" y1="10.184" x2="14.464" y2="11.036"/>
      <line style="opacity: 50%" x1="20.711" y1="4.789" x2="21.563" y2="3.937"/>
      <circle style="opacity: 50%" cx="18" cy="7.5" r="2.169"/>
    </svg>
  </symbol>
  <symbol id="svg-pencil" viewBox="0 0 24 24">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-pencil-code">
      <path d="M4 20h4l10.5 -10.5a2.828 2.828 0 1 0 -4 -4l-10.5 10.5v4" />
      <path d="M13.5 6.5l4 4" />
      <path d="M20 21l2 -2l-2 -2" />
      <path d="M17 17l-2 2l2 2" />
    </svg>
  </symbol>
  <symbol id="svg-eye" viewBox="0 0 24 24">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-eye-code">
      <path stroke="none" d="M0 0h24v24H0z" fill="none" />
      <path d="M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" />
      <path
        d="M11.11 17.958c-3.209 -.307 -5.91 -2.293 -8.11 -5.958c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6c-.21 .352 -.427 .688 -.647 1.008" />
      <path d="M20 21l2 -2l-2 -2" />
      <path d="M17 17l-2 2l2 2" />
    </svg>
  </symbol>
</svg>

<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation">
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc">
<label class="overlay sidebar-overlay" for="__navigation">
  <div class="visually-hidden">Hide navigation sidebar</div>
</label>
<label class="overlay toc-overlay" for="__toc">
  <div class="visually-hidden">Hide table of contents sidebar</div>
</label>

<a class="skip-to-content muted-link" href="#furo-main-content">Skip to content</a>



<div class="page">
  <header class="mobile-header">
    <div class="header-left">
      <label class="nav-overlay-icon" for="__navigation">
        <div class="visually-hidden">Toggle site navigation sidebar</div>
        <i class="icon"><svg><use href="#svg-menu"></use></svg></i>
      </label>
    </div>
    <div class="header-center">
      <a href="#"><div class="brand">TikTokLive v6.6.5</div></a>
    </div>
    <div class="header-right">
      <div class="theme-toggle-container theme-toggle-header">
        <button class="theme-toggle">
          <div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
          <svg class="theme-icon-when-auto-light"><use href="#svg-sun-with-moon"></use></svg>
          <svg class="theme-icon-when-auto-dark"><use href="#svg-moon-with-sun"></use></svg>
          <svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
          <svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
        </button>
      </div>
      <label class="toc-overlay-icon toc-header-icon" for="__toc">
        <div class="visually-hidden">Toggle table of contents sidebar</div>
        <i class="icon"><svg><use href="#svg-toc"></use></svg></i>
      </label>
    </div>
  </header>
  <aside class="sidebar-drawer">
    <div class="sidebar-container">
      
      <div class="sidebar-sticky"><a class="sidebar-brand" href="#">
  
  <div class="sidebar-logo-container">
    <img class="sidebar-logo" src="_static/logo.png" alt="Logo"/>
  </div>
  
  <span class="sidebar-brand-text">TikTokLive v6.6.5</span>
  
</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
  <input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
  <input type="hidden" name="check_keywords" value="yes">
  <input type="hidden" name="area" value="default">
</form>
<div id="searchbox"></div><div class="sidebar-scroll"><div class="sidebar-tree">
  <ul>
<li class="toctree-l1 has-children"><a class="reference internal" href="TikTokLive.html">TikTokLive package</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" role="switch" type="checkbox"/><label for="toctree-checkbox-1"><div class="visually-hidden">Toggle navigation of TikTokLive package</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2 has-children"><a class="reference internal" href="TikTokLive.client.html">TikTokLive.client package</a><input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" role="switch" type="checkbox"/><label for="toctree-checkbox-2"><div class="visually-hidden">Toggle navigation of TikTokLive.client package</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3 has-children"><a class="reference internal" href="TikTokLive.client.web.html">TikTokLive.client.web package</a><input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" role="switch" type="checkbox"/><label for="toctree-checkbox-3"><div class="visually-hidden">Toggle navigation of TikTokLive.client.web package</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l4"><a class="reference internal" href="TikTokLive.client.web.routes.html">TikTokLive.client.web.routes package</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="TikTokLive.client.ws.html">TikTokLive.client.ws package</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="TikTokLive.events.html">TikTokLive.events package</a></li>
<li class="toctree-l2"><a class="reference internal" href="TikTokLive.proto.html">TikTokLive.proto package</a></li>
</ul>
</li>
</ul>

</div>
</div>

      </div>
      
    </div>
  </aside>
  <div class="main">
    <div class="content">
      <div class="article-container">
        <a href="#" class="back-to-top muted-link">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
            <path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12z"></path>
          </svg>
          <span>Back to top</span>
        </a>
        <div class="content-icon-container">
          <div class="view-this-page">
  <a class="muted-link" href="_sources/index.rst.txt" title="View this page">
    <svg><use href="#svg-eye"></use></svg>
    <span class="visually-hidden">View this page</span>
  </a>
</div>
<div class="theme-toggle-container theme-toggle-content">
            <button class="theme-toggle">
              <div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
              <svg class="theme-icon-when-auto-light"><use href="#svg-sun-with-moon"></use></svg>
              <svg class="theme-icon-when-auto-dark"><use href="#svg-moon-with-sun"></use></svg>
              <svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
              <svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
            </button>
          </div>
          <label class="toc-overlay-icon toc-content-icon" for="__toc">
            <div class="visually-hidden">Toggle table of contents sidebar</div>
            <i class="icon"><svg><use href="#svg-toc"></use></svg></i>
          </label>
        </div>
        <article role="main" id="furo-main-content">
          <section id="tiktoklive-docs">
<h1>TikTokLive Docs<a class="headerlink" href="#tiktoklive-docs" title="Link to this heading"></a></h1>
<p>The following subpackages exist for TikTokLive:</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="TikTokLive.html">TikTokLive package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="TikTokLive.html#subpackages">Subpackages</a><ul>
<li class="toctree-l3"><a class="reference internal" href="TikTokLive.client.html">TikTokLive.client package</a></li>
<li class="toctree-l3"><a class="reference internal" href="TikTokLive.events.html">TikTokLive.events package</a></li>
<li class="toctree-l3"><a class="reference internal" href="TikTokLive.proto.html">TikTokLive.proto package</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="TikTokLive.html#module-TikTokLive">Module contents</a></li>
</ul>
</li>
</ul>
</div>
<section id="tiktoklive-python-api-unofficial">
<h2>TikTokLive Python API (Unofficial)<a class="headerlink" href="#tiktoklive-python-api-unofficial" title="Link to this heading"></a></h2>
<p>TikTokLive is an unofficial Python API wrapper for TikTok LIVE written in Python. With this library you can connect to any TikTok livestream and fetch all data available to users in a stream using just a creator’s <code class="docutils literal notranslate"><span class="pre">&#64;unique_id</span></code>.</p>
<p><a class="reference external" href="https://discord.gg/N3KSxzvDX8"><img alt="Discord" src="https://img.shields.io/discord/977648006063091742?logo=discord&amp;label=TikTokLive%20Discord&amp;labelColor=%23171717&amp;color=%231877af" /></a>
<img alt="Connections" src="https://tiktok.eulerstream.com/analytics/pips" />
<img alt="Downloads" src="https://pepy.tech/badge/tiktoklive" />
<img alt="Stars" src="https://img.shields.io/github/stars/isaackogan/TikTokLive?style=flat&amp;color=0274b5" />
<img alt="Forks" src="https://img.shields.io/github/forks/isaackogan/TikTokLive?style=flat&amp;color=0274b5" />
<img alt="Issues" src="https://img.shields.io/github/issues/isaackogan/TikTokLive" /></p>
<blockquote>
<div><p>[!NOTE]
This is <strong>not</strong> a production-ready API. It is a reverse engineering project. Use the <a class="reference external" href="https://www.eulerstream.com/websockets">WebSocket API</a> for production.</p>
</div></blockquote>
<a href="https://www.eulerstream.com/websockets" target="_blank">
    <img src="https://www.eulerstream.com/api/advert?l2=WebSocket+API&r=15&b=1.5&bc=404854&o=0.95"/>
</a>
<!--
Temporarily Removed May 3rd 2025

## Author's Choice

The following are my two favourite enterprise use-cases for the TikTokLive family of libraries. This is <strong>not</strong> paid promotion, and I receive nothing for these recommendations:

<table>
<tr>
    <td><br/><img width="180px" style="border-radius: 10px" src="https://tiktory.com/images/meta/favicon.svg"><br/><br/></td>
    <td>
        <a href="https://www.tiktory.com">
            <strong>Tiktory</strong> provides highly advanced custom overlays, follower alerts, and real-time goal tracking. Seamlessly integrate with OBS and stand out from the crowd!
        </a>
    </td>
</tr>
</table>

<table>
<tr>
    <td><br/><img width="180px" style="border-radius: 10px" src="https://cdn.casterlabs.co/branding/casterlabs/icon.svg"><br/><br/></td>
    <td>
        <a href="https://casterlabs.co/">
            <strong>Casterlabs</strong> is a powerful tool that unifies chats from various streaming platforms, providing a combined chat view, customizable alerts, and handy on-screen widgets for streamers!
        </a>
    </td>
</tr>
</table>

-->
<section id="table-of-contents">
<h3>Table of Contents<a class="headerlink" href="#table-of-contents" title="Link to this heading"></a></h3>
<ul class="simple">
<li><p><a class="reference internal" href="#getting-started"><span class="xref myst">Getting Started</span></a></p>
<ul>
<li><p><a class="reference internal" href="#parameters"><span class="xref myst">Parameters</span></a></p></li>
<li><p><a class="reference internal" href="#methods"><span class="xref myst">Methods</span></a></p></li>
<li><p><a class="reference internal" href="#properties"><span class="xref myst">Properties</span></a></p></li>
<li><p><a class="reference internal" href="#webdefaults"><span class="xref myst">WebDefaults</span></a></p></li>
</ul>
</li>
<li><p><a class="reference external" href="https://isaackogan.github.io/TikTokLive/">Documentation</a></p></li>
<li><p><a class="reference internal" href="#other-languages"><span class="xref myst">Other Languages</span></a></p></li>
<li><p><a class="reference internal" href="#community"><span class="xref myst">Community</span></a></p></li>
<li><p><a class="reference external" href="https://github.com/isaackogan/TikTokLive/tree/master/examples">Examples</a></p></li>
<li><p><a class="reference internal" href="#license"><span class="xref myst">Licensing</span></a></p></li>
<li><p><a class="reference internal" href="#star-history"><span class="xref myst">Star History</span></a></p></li>
<li><p><a class="reference internal" href="TikTokLive.proto.html#TikTokLive.proto.tiktok_proto.CompetitionResultsTeamInfo.contributors" title="TikTokLive.proto.tiktok_proto.CompetitionResultsTeamInfo.contributors"><span class="xref myst py py-attr">Contributors</span></a></p></li>
</ul>
</section>
<section id="community">
<h3>Community<a class="headerlink" href="#community" title="Link to this heading"></a></h3>
<p>Join the <a class="reference external" href="https://discord.gg/e2XwPNTBBr">TikTokLive discord</a> and visit
the <a class="reference external" href="https://discord.gg/uja6SajDxd"><code class="docutils literal notranslate"><span class="pre">#py-support</span></code></a>
channel for questions, contributions and ideas.</p>
</section>
<section id="getting-started">
<h3>Getting Started<a class="headerlink" href="#getting-started" title="Link to this heading"></a></h3>
<ol class="arabic simple">
<li><p>Install the module via pip from the <a class="reference external" href="https://pypi.org/project/TikTokLive/">PyPi</a> repository</p></li>
</ol>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>pip<span class="w"> </span>install<span class="w"> </span>TikTokLive
</pre></div>
</div>
<ol class="arabic simple" start="2">
<li><p>Create your first chat connection</p></li>
</ol>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">TikTokLive</span> <span class="kn">import</span> <span class="n">TikTokLiveClient</span>
<span class="kn">from</span> <span class="nn">TikTokLive.events</span> <span class="kn">import</span> <span class="n">ConnectEvent</span><span class="p">,</span> <span class="n">CommentEvent</span>

<span class="c1"># Create the client</span>
<span class="n">client</span><span class="p">:</span> <span class="n">TikTokLiveClient</span> <span class="o">=</span> <span class="n">TikTokLiveClient</span><span class="p">(</span><span class="n">unique_id</span><span class="o">=</span><span class="s2">&quot;@isaackogz&quot;</span><span class="p">)</span>


<span class="c1"># Listen to an event with a decorator!</span>
<span class="nd">@client</span><span class="o">.</span><span class="n">on</span><span class="p">(</span><span class="n">ConnectEvent</span><span class="p">)</span>
<span class="k">async</span> <span class="k">def</span> <span class="nf">on_connect</span><span class="p">(</span><span class="n">event</span><span class="p">:</span> <span class="n">ConnectEvent</span><span class="p">):</span>
    <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Connected to @</span><span class="si">{</span><span class="n">event</span><span class="o">.</span><span class="n">unique_id</span><span class="si">}</span><span class="s2"> (Room ID: </span><span class="si">{</span><span class="n">client</span><span class="o">.</span><span class="n">room_id</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>


<span class="c1"># Or, add it manually via &quot;client.add_listener()&quot;</span>
<span class="k">async</span> <span class="k">def</span> <span class="nf">on_comment</span><span class="p">(</span><span class="n">event</span><span class="p">:</span> <span class="n">CommentEvent</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
    <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">event</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">nickname</span><span class="si">}</span><span class="s2"> -&gt; </span><span class="si">{</span><span class="n">event</span><span class="o">.</span><span class="n">comment</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>


<span class="n">client</span><span class="o">.</span><span class="n">add_listener</span><span class="p">(</span><span class="n">CommentEvent</span><span class="p">,</span> <span class="n">on_comment</span><span class="p">)</span>

<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="c1"># Run the client and block the main thread</span>
    <span class="c1"># await client.start() to run non-blocking</span>
    <span class="n">client</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
</pre></div>
</div>
<p>For more quickstart examples, see the <a class="reference external" href="https://github.com/isaackogan/TikTokLive/tree/master/examples">examples folder</a>
provided in the source tree.</p>
</section>
<section id="other-languages">
<h3>Other Languages<a class="headerlink" href="#other-languages" title="Link to this heading"></a></h3>
<p>TikTokLive is available in several alternate programming languages:</p>
<ul class="simple">
<li><p><strong>Node.JS:</strong> <a class="reference external" href="https://github.com/zerodytrash/TikTok-Live-Connector">https://github.com/zerodytrash/TikTok-Live-Connector</a></p></li>
<li><p><strong>Java:</strong> <a class="reference external" href="https://github.com/jwdeveloper/TikTok-Live-Java">https://github.com/jwdeveloper/TikTok-Live-Java</a></p></li>
<li><p><strong>C#/Unity:</strong> <a class="reference external" href="https://github.com/frankvHoof93/TikTokLiveSharp">https://github.com/frankvHoof93/TikTokLiveSharp</a></p></li>
<li><p><strong>Go:</strong> <a class="reference external" href="https://github.com/steampoweredtaco/gotiktoklive">https://github.com/steampoweredtaco/gotiktoklive</a></p></li>
<li><p><strong>Rust:</strong> <a class="reference external" href="https://github.com/jwdeveloper/TikTokLiveRust">https://github.com/jwdeveloper/TikTokLiveRust</a></p></li>
</ul>
</section>
<section id="parameters">
<h3>Parameters<a class="headerlink" href="#parameters" title="Link to this heading"></a></h3>
<div class="table-wrapper colwidths-auto docutils container">
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Param Name</p></th>
<th class="head"><p>Required</p></th>
<th class="head"><p>Default</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>unique_id</p></td>
<td><p>Yes</p></td>
<td><p>N/A</p></td>
<td><p>The unique username of the broadcaster. You can find this name in the URL of the user. For example, the <code class="docutils literal notranslate"><span class="pre">unique_id</span></code> for <a class="reference external" href="https://www.tiktok.com/&#64;isaackogz"><code class="docutils literal notranslate"><span class="pre">https://www.tiktok.com/&#64;isaackogz</span></code></a> would be <code class="docutils literal notranslate"><span class="pre">isaackogz</span></code>.</p></td>
</tr>
<tr class="row-odd"><td><p>web_proxy</p></td>
<td><p>No</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">None</span></code></p></td>
<td><p>TikTokLive supports proxying HTTP requests. This parameter accepts an <code class="docutils literal notranslate"><span class="pre">httpx.Proxy</span></code>. Note that if you do use a proxy you may be subject to reduced connection limits at times of high load.</p></td>
</tr>
<tr class="row-even"><td><p>ws_proxy</p></td>
<td><p>No</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">None</span></code></p></td>
<td><p>TikTokLive supports proxying the websocket connection. This parameter accepts an <code class="docutils literal notranslate"><span class="pre">httpx.Proxy</span></code>. Using this proxy will never be subject to reduced connection limits.</p></td>
</tr>
<tr class="row-odd"><td><p>web_kwargs</p></td>
<td><p>No</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{}</span></code></p></td>
<td><p>Under the scenes, the TikTokLive HTTP client uses the <a class="reference external" href="https://github.com/encode/httpx"><code class="docutils literal notranslate"><span class="pre">httpx</span></code></a> library. Arguments passed to <code class="docutils literal notranslate"><span class="pre">web_kwargs</span></code> will be forward the the underlying HTTP client.</p></td>
</tr>
<tr class="row-even"><td><p>ws_kwargs</p></td>
<td><p>No</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{}</span></code></p></td>
<td><p>Under the scenes, TikTokLive uses the <a class="reference external" href="https://github.com/python-websockets/websockets"><code class="docutils literal notranslate"><span class="pre">websockets</span></code></a> library to connect to TikTok. Arguments passed to <code class="docutils literal notranslate"><span class="pre">ws_kwargs</span></code> will be forwarded to the underlying WebSocket client.</p></td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="methods">
<h3>Methods<a class="headerlink" href="#methods" title="Link to this heading"></a></h3>
<p>A <code class="docutils literal notranslate"><span class="pre">TikTokLiveClient</span></code> object contains the following methods worth mentioning:</p>
<div class="table-wrapper colwidths-auto docutils container">
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Method Name</p></th>
<th class="head"><p>Notes</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>run</p></td>
<td><p>N/A</p></td>
<td><p>Connect to the livestream and block the main thread. This is best for small scripts.</p></td>
</tr>
<tr class="row-odd"><td><p>add_listener</p></td>
<td><p>N/A</p></td>
<td><p>Adds an <em>asynchronous</em> listener function (or, you can decorate a function with <code class="docutils literal notranslate"><span class="pre">&#64;client.on(Type[Event])</span></code>) and takes two parameters, an event name and the payload, an AbstractEvent</p></td>
</tr>
<tr class="row-even"><td><p>connect</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">async</span></code></p></td>
<td><p>Connects to the tiktok live chat while blocking the current future. When the connection ends (e.g. livestream is over), the future is released.</p></td>
</tr>
<tr class="row-odd"><td><p>start</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">async</span></code></p></td>
<td><p>Connects to the live chat without blocking the main thread. This returns an <code class="docutils literal notranslate"><span class="pre">asyncio.Task</span></code> object with the client loop.</p></td>
</tr>
<tr class="row-even"><td><p>disconnect</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">async</span></code></p></td>
<td><p>Disconnects the client from the websocket gracefully, processing remaining events before ending the client loop.</p></td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="properties">
<h3>Properties<a class="headerlink" href="#properties" title="Link to this heading"></a></h3>
<p>A <code class="docutils literal notranslate"><span class="pre">TikTokLiveClient</span></code> object contains the following important properties:</p>
<div class="table-wrapper colwidths-auto docutils container">
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Attribute Name</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>room_id</p></td>
<td><p>The Room ID of the livestream room the client is currently connected to.</p></td>
</tr>
<tr class="row-odd"><td><p>web</p></td>
<td><p>The TikTok HTTP client. This client has a lot of useful routes you should explore!</p></td>
</tr>
<tr class="row-even"><td><p>connected</p></td>
<td><p>Whether you are currently connected to the livestream.</p></td>
</tr>
<tr class="row-odd"><td><p>logger</p></td>
<td><p>The internal logger used by TikTokLive. You can use <code class="docutils literal notranslate"><span class="pre">client.logger.setLevel(...)</span></code> method to enable client debug.</p></td>
</tr>
<tr class="row-even"><td><p>room_info</p></td>
<td><p>Room information that is retrieved from TikTok when you use a connection method (e.g. <code class="docutils literal notranslate"><span class="pre">client.connect</span></code>) with the keyword argument <code class="docutils literal notranslate"><span class="pre">fetch_room_info=True</span></code> .</p></td>
</tr>
<tr class="row-odd"><td><p>gift_info</p></td>
<td><p>Extra gift information that is retrieved from TikTok when you use a connection method (e.g. <code class="docutils literal notranslate"><span class="pre">client.run</span></code>) with the keyword argument <code class="docutils literal notranslate"><span class="pre">fetch_gift_info=True</span></code>.</p></td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="webdefaults">
<h3>WebDefaults<a class="headerlink" href="#webdefaults" title="Link to this heading"></a></h3>
<p>TikTokLive has a series of global defaults used to create the HTTP client which you can customize. For info on how to set these parameters, see
the <a class="reference external" href="https://github.com/isaackogan/TikTokLive/blob/master/examples/web_defaults.py">web_defaults.py</a> example.</p>
<div class="table-wrapper colwidths-auto docutils container">
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Parameter</p></th>
<th class="head"><p>Type</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>tiktok_sign_api_key</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">str</span></code></p></td>
<td><p>A <a class="reference external" href="https://www.eulerstream.com/">Euler Stream</a> API key used to increase rate limits.</p></td>
</tr>
<tr class="row-odd"><td><p>tiktok_app_url</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">str</span></code></p></td>
<td><p>The TikTok app URL (<code class="docutils literal notranslate"><span class="pre">https://www.tiktok.com</span></code>) used to scrape the room.</p></td>
</tr>
<tr class="row-even"><td><p>tiktok_sign_url</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">str</span></code></p></td>
<td><p>The <a class="reference external" href="https://www.eulerstream.com/">signature server</a> used to generate tokens to connect to TikTokLive. By default, this is Euler Stream, but you can swap your own with ease.</p></td>
</tr>
<tr class="row-odd"><td><p>tiktok_webcast_url</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">str</span></code></p></td>
<td><p>The TikTok livestream URL (<code class="docutils literal notranslate"><span class="pre">https://webcast.tiktok.com</span></code>) where livestreams can be accessed from.</p></td>
</tr>
<tr class="row-even"><td><p>web_client_params</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">dict</span></code></p></td>
<td><p>The URL parameters added on to TikTok requests from the HTTP client.</p></td>
</tr>
<tr class="row-odd"><td><p>web_client_headers</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">dict</span></code></p></td>
<td><p>The headers added on to TikTok requests from the HTTP client.</p></td>
</tr>
<tr class="row-even"><td><p>web_client_cookies</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">dict</span></code></p></td>
<td><p>Custom cookies to initialize the http client with.</p></td>
</tr>
<tr class="row-odd"><td><p>ws_client_params</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">dict</span></code></p></td>
<td><p>The URL parameters added to the URI when connecting to TikTok’s Webcast WebSocket server.</p></td>
</tr>
<tr class="row-even"><td><p>ws_client_params_append_str</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">dict</span></code></p></td>
<td><p>Extra string data to append to the TikTokLive WebSocket connection URI.</p></td>
</tr>
<tr class="row-odd"><td><p>ws_client_headers</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">dict</span></code></p></td>
<td><p>Extra headers to append to the TikTokLive WebSocket client.</p></td>
</tr>
<tr class="row-even"><td><p>ja3_impersonate</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">str</span></code></p></td>
<td><p>The ja3 fingerprint to impersonate. This should match whatever the current version is on the Sign Server, or “privileged” methods will fail.</p></td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="events">
<h3>Events<a class="headerlink" href="#events" title="Link to this heading"></a></h3>
<p>Events can be listened to using a decorator or non-decorator method call. The following examples illustrate how you can listen to an event:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="nd">@client</span><span class="o">.</span><span class="n">on</span><span class="p">(</span><span class="n">LikeEvent</span><span class="p">)</span>
<span class="k">async</span> <span class="k">def</span> <span class="nf">on_like</span><span class="p">(</span><span class="n">event</span><span class="p">:</span> <span class="n">LikeEvent</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
    <span class="o">...</span>


<span class="k">async</span> <span class="k">def</span> <span class="nf">on_comment</span><span class="p">(</span><span class="n">event</span><span class="p">:</span> <span class="n">CommentEvent</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
    <span class="o">...</span>


<span class="n">client</span><span class="o">.</span><span class="n">add_listener</span><span class="p">(</span><span class="n">CommentEvent</span><span class="p">,</span> <span class="n">on_comment</span><span class="p">)</span>
</pre></div>
</div>
<p>There are two types of events, <a class="reference external" href="https://github.com/isaackogan/TikTokLive/blob/master/TikTokLive/events/custom_events.py"><code class="docutils literal notranslate"><span class="pre">CustomEvent</span></code></a>
events and <a class="reference external" href="https://github.com/isaackogan/TikTokLive/blob/master/TikTokLive/events/proto_events.py"><code class="docutils literal notranslate"><span class="pre">ProtoEvent</span></code></a> events.
Both belong to the TikTokLive <code class="docutils literal notranslate"><span class="pre">Event</span></code> type and can be listened to. The following events are available:</p>
<section id="custom-events">
<h4>Custom Events<a class="headerlink" href="#custom-events" title="Link to this heading"></a></h4>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">ConnectEvent</span></code> - Triggered when the Webcast connection is initiated</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">DisconnectEvent</span></code> - Triggered when the Webcast connection closes (including the livestream ending)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">LiveEndEvent</span></code> - Triggered when the livestream ends</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">LivePauseEvent</span></code> - Triggered when the livestream is paused</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">LiveUnpauseEvent</span></code> - Triggered when the livestream is unpaused</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">FollowEvent</span></code> - Triggered when a user in the livestream follows the streamer</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ShareEvent</span></code> - Triggered when a user shares the livestream</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">WebsocketResponseEvent</span></code> - Triggered when any event is received (contains the event)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">UnknownEvent</span></code> - An instance of <code class="docutils literal notranslate"><span class="pre">WebsocketResponseEvent</span></code> thrown whenever an event does not have an existing definition, useful for debugging</p></li>
</ul>
</section>
<section id="proto-events">
<h4>Proto Events<a class="headerlink" href="#proto-events" title="Link to this heading"></a></h4>
<p>If you know what an event does, <a class="reference external" href="https://github.com/isaackogan/TikTokLive/pulls">make a pull request</a> and add the description.</p>
<details>
<summary><h4>Proto Events</h4></summary>
<ul>
<li><code>GiftEvent</code> - Triggered when a gift is sent to the streamer</li>
<li><code>GoalUpdateEvent</code> - Triggered when the subscriber goal is updated</li>
<li><code>ControlEvent</code> - Triggered when a stream action occurs (e.g. Livestream start, end)</li>
<li><code>LikeEvent</code> - Triggered when the stream receives a like</li>
<li><code>SubscribeEvent</code> - Triggered when someone subscribes to the TikTok creator</li>
<li><code>PollEvent</code> - Triggered when the creator launches a new poll</li>
<li><code>CommentEvent</code> - Triggered when a comment is sent in the stream</li>
<li><code>RoomEvent</code> - Messages broadcasted to all users in the room (e.g. "Welcome to TikTok LIVE!")</li>
<li><code>EmoteChatEvent</code> - Triggered when a custom emote is sent in the chat</li>
<li><code>EnvelopeEvent</code> - Triggered every time someone sends a treasure chest</li>
<li><code>SocialEvent</code> - Triggered when a user shares the stream or follows the host</li>
<li><code>QuestionNewEvent</code> - Triggered every time someone asks a new question via the question feature</li>
<li><code>LiveIntroEvent</code> - Triggered when a live intro message appears</li>
<li><code>LinkMicArmiesEvent</code> - Triggered when a TikTok battle user receives points</li>
<li><code>LinkMicBattleEvent</code> - Triggered when a TikTok battle is started</li>
<li><code>JoinEvent</code> - Triggered when a user joins the livestream</li>
<li><code>LinkMicFanTicketMethodEvent</code></li>
<li><code>LinkMicMethodEvent</code></li>
<li><code>BarrageEvent</code> - Triggered when a "VIP" viewer (based on their gifting level) joins the live chat room</li>
<li><code>CaptionEvent</code></li>
<li><code>ImDeleteEvent</code> - Triggered when a viewer's messages are deleted</li>
<li><code>RoomUserSeqEvent</code> - Current viewer count information</li>
<li><code>RankUpdateEvent</code></li>
<li><code>RankTextEvent</code> - Triggered when gift count makes a viewer one of the top three</li>
<li><code>HourlyRankEvent</code></li>
<li><code>UnauthorizedMemberEvent</code></li>
<li><code>MessageDetectEvent</code></li>
<li><code>OecLiveShoppingEvent</code></li>
<li><code>RoomPinEvent</code> - Triggered when a message is pinned</li>
<li><code>SystemEvent</code></li>
<li><code>LinkEvent</code></li>
<li><code>LinkLayerEvent</code></li>
<li><code>KaraokeQueueListEvent</code></li>
<li><code>GroupLiveMemberNotifyEvent</code></li>
<li><code>SubscriptionGuideEvent</code></li>
<li><code>NoticeboardReviewEvent</code></li>
<li><code>BottomEvent</code></li>
<li><code>CapsuleEvent</code></li>
<li><code>LinkMicBattleEvent</code></li>
<li><code>QuestionSelectedEvent</code></li>
<li><code>TrayEvent</code></li>
<li><code>AssetEvent</code></li>
<li><code>WalletLiveRewardsRatioEvent</code></li>
<li><code>LinkScreenChangeEvent</code></li>
<li><code>PartnershipPunishEvent</code></li>
<li><code>GiftPanelUpdateEvent</code></li>
<li><code>AnchorTaskReminderEvent</code></li>
<li><code>LinkBusinessEvent</code></li>
<li><code>MarqueeAnnouncementEvent</code></li>
<li><code>GiftDynamicRestrictionEvent</code></li>
<li><code>CommonPopupEvent</code></li>
<li><code>EcBarrageEvent</code></li>
<li><code>PromoteAdStatusEvent</code></li>
<li><code>InteractionHubGoalEvent</code></li>
<li><code>EpiEvent</code></li>
<li><code>LinkmicAnimationEvent</code></li>
<li><code>KaraokeYouSingReqEvent</code></li>
<li><code>RealTimePerformancePageEvent</code></li>
<li><code>StreamStatusEvent</code></li>
<li><code>GiftCollectionUpdateEvent</code></li>
<li><code>CommercialCustomEvent</code></li>
<li><code>GuideEvent</code></li>
<li><code>DonationEvent</code></li>
<li><code>LiveGameIntroEvent</code></li>
<li><code>PartnershipDropsCardChangeEvent</code></li>
<li><code>GameGuessWidgetsEvent</code></li>
<li><code>MiddleTouchEvent</code></li>
<li><code>UserStatsEvent</code></li>
<li><code>WallpaperReviewEvent</code></li>
<li><code>LinkMicAdEvent</code></li>
<li><code>SubTimerStickerEvent</code></li>
<li><code>GiftGalleryEvent</code></li>
<li><code>GiftUpdateEvent</code></li>
<li><code>NoticeboardEvent</code></li>
<li><code>UpgradeEvent</code></li>
<li><code>BackpackEvent</code></li>
<li><code>AvatarStyleResultEvent</code></li>
<li><code>GameSettingChangeEvent</code></li>
<li><code>PartnershipDropsUpdateEvent</code></li>
<li><code>QuestionSwitchEvent</code></li>
<li><code>LiveInfoAuditNoticeEvent</code></li>
<li><code>CommonToastEvent</code></li>
<li><code>ToastEvent</code></li>
<li><code>DonationStickerModifyMethodEvent</code></li>
<li><code>PollEvent</code></li>
<li><code>HighlightFragementReadyEvent</code></li>
<li><code>GiftPromptEvent</code></li>
<li><code>ForceFetchRecommendationsEvent</code></li>
<li><code>GameGuessPinCardEvent</code></li>
<li><code>LinkLayoutEvent</code></li>
<li><code>GameOcrPingEvent</code></li>
<li><code>AnchorGrowLevelEvent</code></li>
<li><code>EnvelopePortalEvent</code></li>
<li><code>CohostReserveEvent</code></li>
<li><code>BaLeadGenEvent</code></li>
<li><code>PictionaryEndEvent</code></li>
<li><code>RoomNotifyEvent</code></li>
<li><code>FansEventEvent</code></li>
<li><code>KaraokeQueueEvent</code></li>
<li><code>FollowCardEvent</code></li>
<li><code>ActivityQuizUserIdentityEvent</code></li>
<li><code>LiveJourneyEvent</code></li>
<li><code>CommentsEvent</code></li>
<li><code>WeeklyRankRewardEvent</code></li>
<li><code>LinkStateEvent</code></li>
<li><code>AccessRecallEvent</code></li>
<li><code>AiSummaryEvent</code></li>
<li><code>PerceptionEvent</code></li>
<li><code>RoomVerifyEvent</code></li>
<li><code>GuideTaskEvent</code></li>
<li><code>VideoLiveCouponRcmdEvent</code></li>
<li><code>VideoLiveGoodsRcmdEvent</code></li>
<li><code>KaraokeSwitchEvent</code></li>
<li><code>PrivilegeAdvanceEvent</code></li>
<li><code>LinkMicBattlePunishFinishEvent</code></li>
<li><code>BoostedUsersEvent</code></li>
<li><code>RankToastEvent</code></li>
<li><code>CommentTrayEvent</code></li>
<li><code>AnchorReminderWordEvent</code></li>
<li><code>PaidContentLiveShoppingEvent</code></li>
<li><code>RoomEventEvent</code></li>
<li><code>RoomBottomEvent</code></li>
<li><code>DonationInfoEvent</code></li>
<li><code>GameMomentEvent</code></li>
<li><code>HashtagEvent</code></li>
<li><code>LinkMicBattleItemCardEvent</code></li>
<li><code>PrivilegeDynamicEffectEvent</code></li>
<li><code>AnchorGetSubQuotaEvent</code></li>
<li><code>OecLiveHotRoomEvent</code></li>
<li><code>AudienceReserveUserStateEvent</code></li>
<li><code>RealtimeLiveCenterMethodEvent</code></li>
<li><code>WallpaperEvent</code></li>
<li><code>SubPinEventEvent</code></li>
<li><code>LinkmicBattleTaskEvent</code></li>
<li><code>StarCommentPushEvent</code></li>
<li><code>EcTaskRefreshCouponListEvent</code></li>
<li><code>ShortTouchEvent</code></li>
<li><code>EffectControlEvent</code></li>
<li><code>KaraokeRedDotEvent</code></li>
<li><code>QuestionDeleteEvent</code></li>
<li><code>InRoomBannerEvent</code></li>
<li><code>ShareGuideEvent</code></li>
<li><code>EventEvent</code></li>
<li><code>InRoomBannerEventEvent</code></li>
<li><code>PlayTogetherEvent</code></li>
<li><code>SubContractStatusEvent</code></li>
<li><code>HourlyRankRewardEvent</code></li>
<li><code>PictionaryStartEvent</code></li>
<li><code>GuestInviteEvent</code></li>
<li><code>NoticeEvent</code></li>
<li><code>PartnershipDownloadCountEvent</code></li>
<li><code>GreetingEvent</code></li>
<li><code>LiveShowEvent</code></li>
<li><code>SubWaveEvent</code></li>
<li><code>GameReqSetGuessEvent</code></li>
<li><code>SpeakerEvent</code></li>
<li><code>LinkMicAnchorGuideEvent</code></li>
<li><code>CompetitionEvent</code></li>
<li><code>AvatarReportDeleteEvent</code></li>
<li><code>EffectPreloadingEvent</code></li>
<li><code>ColdStartEvent</code></li>
<li><code>CountdownForAllEvent</code></li>
<li><code>GiftBroadcastEvent</code></li>
<li><code>PreviewGameMomentEvent</code></li>
<li><code>GameRecommendCreateGuessEvent</code></li>
<li><code>VideoLiveGoodsOrderEvent</code></li>
<li><code>StarCommentNotificationEvent</code></li>
<li><code>InRoomBannerRefreshEvent</code></li>
<li><code>RoomStickerEvent</code></li>
<li><code>GiftProgressEvent</code></li>
<li><code>OecLiveManagerEvent</code></li>
<li><code>DiggEvent</code></li>
<li><code>AiLiveSummaryEvent</code></li>
<li><code>AnchorToolModificationEvent</code></li>
<li><code>MgPunishCenterActionEvent</code></li>
<li><code>PictionaryExitEvent</code></li>
<li><code>CountdownEvent</code></li>
<li><code>GameServerFeatureEvent</code></li>
<li><code>PlaybookEvent</code></li>
<li><code>GiftRecordCapsuleEvent</code></li>
<li><code>QuickChatListEvent</code></li>
<li><code>PartnershipCardChangeEvent</code></li>
<li><code>ScreenChatEvent</code></li>
<li><code>GameEmoteUpdateEvent</code></li>
<li><code>BoostCardEvent</code></li>
<li><code>RoomStreamAdaptationEvent</code></li>
<li><code>LinkmicBattleNoticeEvent</code></li>
<li><code>GoodyBagEvent</code></li>
</ul>
</details>
</section>
<section id="special-events">
<h4>Special Events<a class="headerlink" href="#special-events" title="Link to this heading"></a></h4>
</section>
<section id="giftevent">
<h4><code class="docutils literal notranslate"><span class="pre">GiftEvent</span></code><a class="headerlink" href="#giftevent" title="Link to this heading"></a></h4>
<p>Triggered every time a gift arrives. Extra information can be gleamed from the <code class="docutils literal notranslate"><span class="pre">available_gifts</span></code> client attribute.</p>
<blockquote>
<div><p><strong>NOTE:</strong> Users have the capability to send gifts in a streak. This increases the <code class="docutils literal notranslate"><span class="pre">event.gift.repeat_count</span></code> value until the
user terminates the streak. During this time new gift events are triggered again and again with an
increased <code class="docutils literal notranslate"><span class="pre">event.gift.repeat_count</span></code> value. It should be noted that after the end of a streak, a final gift event is
triggered, which signals the end of the streak with <code class="docutils literal notranslate"><span class="pre">event.repeat_end</span></code>:<code class="docutils literal notranslate"><span class="pre">1</span></code>. The following handlers show how you can deal with this in your code.</p>
</div></blockquote>
<p>Using the low-level direct proto:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="nd">@client</span><span class="o">.</span><span class="n">on</span><span class="p">(</span><span class="n">GiftEvent</span><span class="p">)</span>
<span class="k">async</span> <span class="k">def</span> <span class="nf">on_gift</span><span class="p">(</span><span class="n">event</span><span class="p">:</span> <span class="n">GiftEvent</span><span class="p">):</span>
    <span class="c1"># If it&#39;s type 1 and the streak is over</span>
    <span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">gift</span><span class="o">.</span><span class="n">info</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">gift</span><span class="o">.</span><span class="n">is_repeating</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">event</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">unique_id</span><span class="si">}</span><span class="s2"> sent </span><span class="si">{</span><span class="n">event</span><span class="o">.</span><span class="n">repeat_count</span><span class="si">}</span><span class="s2">x </span><span class="se">\&quot;</span><span class="si">{</span><span class="n">event</span><span class="o">.</span><span class="n">gift</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="se">\&quot;</span><span class="s2">&quot;</span><span class="p">)</span>

    <span class="c1"># It&#39;s not type 1, which means it can&#39;t have a streak &amp; is automatically over</span>
    <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">gift</span><span class="o">.</span><span class="n">info</span><span class="o">.</span><span class="n">type</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">event</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">unique_id</span><span class="si">}</span><span class="s2"> sent </span><span class="se">\&quot;</span><span class="si">{</span><span class="n">event</span><span class="o">.</span><span class="n">gift</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="se">\&quot;</span><span class="s2">&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>Using the TikTokLive extended proto:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="nd">@client</span><span class="o">.</span><span class="n">on</span><span class="p">(</span><span class="s2">&quot;gift&quot;</span><span class="p">)</span>
<span class="k">async</span> <span class="k">def</span> <span class="nf">on_gift</span><span class="p">(</span><span class="n">event</span><span class="p">:</span> <span class="n">GiftEvent</span><span class="p">):</span>
    <span class="c1"># Streakable gift &amp; streak is over</span>
    <span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">gift</span><span class="o">.</span><span class="n">streakable</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">event</span><span class="o">.</span><span class="n">streaking</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">event</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">unique_id</span><span class="si">}</span><span class="s2"> sent </span><span class="si">{</span><span class="n">event</span><span class="o">.</span><span class="n">repeat_count</span><span class="si">}</span><span class="s2">x </span><span class="se">\&quot;</span><span class="si">{</span><span class="n">event</span><span class="o">.</span><span class="n">gift</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="se">\&quot;</span><span class="s2">&quot;</span><span class="p">)</span>

    <span class="c1"># Non-streakable gift</span>
    <span class="k">elif</span> <span class="ow">not</span> <span class="n">event</span><span class="o">.</span><span class="n">gift</span><span class="o">.</span><span class="n">streakable</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">event</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">unique_id</span><span class="si">}</span><span class="s2"> sent </span><span class="se">\&quot;</span><span class="si">{</span><span class="n">event</span><span class="o">.</span><span class="n">gift</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="se">\&quot;</span><span class="s2">&quot;</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="subscribeevent">
<h4><code class="docutils literal notranslate"><span class="pre">SubscribeEvent</span></code><a class="headerlink" href="#subscribeevent" title="Link to this heading"></a></h4>
<p>This event will only fire when a session ID (account login) is passed to the HTTP client <em>before</em> connecting to TikTok LIVE.
You can set the session ID with <a class="reference external" href="https://github.com/isaackogan/TikTokLive/blob/master/examples/logged_in.py"><code class="docutils literal notranslate"><span class="pre">client.web.set_session_id(...)</span></code></a>.</p>
</section>
</section>
<section id="checking-if-a-user-is-live">
<h3>Checking If A User Is Live<a class="headerlink" href="#checking-if-a-user-is-live" title="Link to this heading"></a></h3>
<p>It is considered inefficient to use the connect method to check if a user is live. It is better to use the dedicated <code class="docutils literal notranslate"><span class="pre">await</span> <span class="pre">client.is_live()</span></code> method.</p>
<p>There is a <a class="reference external" href="https://github.com/isaackogan/TikTokLive/blob/master/examples/check_live.py">complete example</a> of how to do this in the <a class="reference external" href="https://github.com/isaackogan/TikTokLive/tree/master/examples">examples</a> folder.</p>
</section>
<section id="star-history">
<h3>Star History<a class="headerlink" href="#star-history" title="Link to this heading"></a></h3>
<p align="center">
    <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=isaackogan/TikTokLive&type=Date&theme=dark" onerror="this.src='https://api.star-history.com/svg?repos=isaackogan/TikTokLive&type=Date'" />
</p>
</section>
<section id="license">
<h3>License<a class="headerlink" href="#license" title="Link to this heading"></a></h3>
<p>This project is licensed under the MIT License - see the <a class="reference internal" href="#LICENSE"><span class="xref myst">LICENSE</span></a> file for details.</p>
</section>
<section id="contributors">
<h3>Contributors<a class="headerlink" href="#contributors" title="Link to this heading"></a></h3>
<ul class="simple">
<li><p><strong>Isaac Kogan</strong> - <em>Creator, Primary Maintainer, and Reverse-Engineering</em> - <a class="reference external" href="https://github.com/isaackogan">isaackogan</a></p></li>
<li><p><strong>Zerody</strong> - <em>Creator of the NodeJS library, introduced me to scraping TikTok LIVE</em> - <a class="reference external" href="https://github.com/zerodytrash/">Zerody</a></p></li>
</ul>
<p>See also the full list of secondary <a class="reference external" href="https://github.com/isaackogan/TikTokLive/contributors">contributors</a> who have participated in
this project.</p>
</section>
</section>
</section>

        </article>
      </div>
      <footer>
        
        <div class="related-pages">
          <a class="next-page" href="TikTokLive.html">
              <div class="page-info">
                <div class="context">
                  <span>Next</span>
                </div>
                <div class="title">TikTokLive package</div>
              </div>
              <svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
            </a>
          
        </div>
        <div class="bottom-of-page">
          <div class="left-details">
            <div class="copyright">
                Copyright &#169; 2022, Isaac Kogan
            </div>
            Made with <a href="https://www.sphinx-doc.org/">Sphinx</a> and <a class="muted-link" href="https://pradyunsg.me">@pradyunsg</a>'s
            
            <a href="https://github.com/pradyunsg/furo">Furo</a>
            
          </div>
          <div class="right-details">
            
          </div>
        </div>
        
      </footer>
    </div>
    <aside class="toc-drawer">
      
      
      <div class="toc-sticky toc-scroll">
        <div class="toc-title-container">
          <span class="toc-title">
            On this page
          </span>
        </div>
        <div class="toc-tree-container">
          <div class="toc-tree">
            <ul>
<li><a class="reference internal" href="#">TikTokLive Docs</a><ul>
<li><a class="reference internal" href="#tiktoklive-python-api-unofficial">TikTokLive Python API (Unofficial)</a><ul>
<li><a class="reference internal" href="#table-of-contents">Table of Contents</a></li>
<li><a class="reference internal" href="#community">Community</a></li>
<li><a class="reference internal" href="#getting-started">Getting Started</a></li>
<li><a class="reference internal" href="#other-languages">Other Languages</a></li>
<li><a class="reference internal" href="#parameters">Parameters</a></li>
<li><a class="reference internal" href="#methods">Methods</a></li>
<li><a class="reference internal" href="#properties">Properties</a></li>
<li><a class="reference internal" href="#webdefaults">WebDefaults</a></li>
<li><a class="reference internal" href="#events">Events</a><ul>
<li><a class="reference internal" href="#custom-events">Custom Events</a></li>
<li><a class="reference internal" href="#proto-events">Proto Events</a></li>
<li><a class="reference internal" href="#special-events">Special Events</a></li>
<li><a class="reference internal" href="#giftevent"><code class="docutils literal notranslate"><span class="pre">GiftEvent</span></code></a></li>
<li><a class="reference internal" href="#subscribeevent"><code class="docutils literal notranslate"><span class="pre">SubscribeEvent</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#checking-if-a-user-is-live">Checking If A User Is Live</a></li>
<li><a class="reference internal" href="#star-history">Star History</a></li>
<li><a class="reference internal" href="#license">License</a></li>
<li><a class="reference internal" href="#contributors">Contributors</a></li>
</ul>
</li>
</ul>
</li>
</ul>

          </div>
        </div>
      </div>
      
      
    </aside>
  </div>
</div><script src="_static/jquery.js?v=5d32c60e"></script>
    <script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
    <script src="_static/documentation_options.js?v=5929fcd5"></script>
    <script src="_static/doctools.js?v=9a2dae69"></script>
    <script src="_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="_static/scripts/furo.js?v=5fa4622c"></script>
    <script src="_static/js/rtd_search_config.js?v=b0596c34"></script>
    <script src="_static/js/rtd_sphinx_search.min.js?v=5e065386"></script>
    </body>
</html>